<?php
defined('SEJUJOPEFDNGJSL') or exit('Access denied');

$pagecount=getnums($_GET["pagecount"],$GLOBALARR['pagecount']);
$option=getnums($_GET['option'],1);
$orderby=getnums($_GET['orderby'],1);
$quser=trim($_GET['quser']);

$tmp_arr['toption'].='<a href="'.getqueurl('option',1).'" class="'.geteqval(array($option,1,'taselbtn','thabtn')).'">今日新增</a>'
        . '<a href="'.getqueurl('option',2).'" class="'.geteqval(array($option,2,'taselbtn','thabtn')).'">全部</a>'
        . '<a href="'.getqueurl('option',3).'" class="'.geteqval(array($option,3,'taselbtn','thabtn')).'">正在收益中</a>'
        . '<a href="'.getqueurl('option',4).'" class="'.geteqval(array($option,4,'taselbtn','thabtn')).'">已完成收益</a>'
        // . '<a href="'.getqueurl('option',5).'" class="'.geteqval(array($option,5,'taselbtn','thabtn')).'">管理员指定获取收益</a>'
        // . '<a href="'.getqueurl('option',6).'" class="'.geteqval(array($option,6,'taselbtn','thabtn')).'">已中断收益</a>'
        // . '<a href="'.getqueurl('option',7).'" class="'.geteqval(array($option,7,'taselbtn','thabtn')).'">可中断收益</a>'
        ;


$tmp_arr['torderby']='<a href="'.getqueurl('orderby',geteqval(array($orderby,1,'2','1'))).'" class="'.((strstr($orderby,'1')||strstr($orderby,'2'))?"tpaixusel":"tpaixu").'">'.geteqval(array($orderby,1,'时间↓','时间↑')).'</a>';

if(is_array($GLOBALARR['jjname'])){
	foreach ($GLOBALARR['jjname'] as $k => $v) {
		$tmp_arr['tcolor'].='<a href="javascript:;" class="theacolor levelcolor'.$k.'">'.$v.'</a>';
	}
}

$condition=' where 1=1 ';

if($quser){
	if(strstr($quser,'-')){
		$qdate=explode('-',$quser);
		if($qdate[0]) $condition.=" and from_unixtime(give_help_time,'%Y')=".$qdate[0]."";
		if($qdate[1]) $condition.=" and from_unixtime(give_help_time,'%m')=".$qdate[1]."";
		if($qdate[2]) $condition.=" and from_unixtime(give_help_time,'%d')=".$qdate[2]."";
	}else{
		$qno = substr($quser,1,strlen($quser)-1);
		$queryno = dncorder($qno);
		$condition.=" and uname like '%".$quser."%' or give_help_no like '%".$queryno."%'";
	}
}
//status :0等待对配1等待打款2配对已过期3已取消 status_value:0收益中1收益结束2中断收益结束
if($option==1) $condition.=" and from_unixtime(give_help_time,'%Y-%m-%d')='".date('Y-m-d')."'";
if($option==3) $condition.=' and `status`=0 ';//3正在收益中    
if($option==4) $condition.=' and status=1';//4已完成收益【达到利息出局天数】
if($option==5) $condition.=' and `status`=2';//5已过期收益
if($option==6) $condition.=' and status_value=2';//6已中断收益
//7可中断收益：$arr['status_value']==0&&$arr['benifit_times']>=$GLOBALARR["jjsyt"]&&$arr["amount"]==$arr["helper_confirm_amount"]
if($option==7) $condition.=' and `status`<>2 and `status`<>3 and status_value=0 and benifit_times>='.$GLOBALARR["jjsyt"].' and amount=helper_confirm_amount';//7 可中断收益【即已经有matched time的排单】
//echo $condition;
$order='';
if($orderby==1) $order=' order by give_help_time desc';
if($orderby==2) $order=' order by give_help_time asc';


$tmp_arr['tth']='<th>序号</th><th>排单编号</th><th>排单会员</th><th>添加时间</th><th>排单金额</th><th>已分利息次数</th><th>已分利息金额</th><th>状态</th>';


$psql="select count(0) from ld_give_help $condition";
$db->query($psql,3);
$pcount=$db->fval;
$pagecount=$pagecount;   //每页条数 
$astr="&lsaction=lockip&pagecount=$pagecount&orderby=$orderby&option=$option&quser=$quser";	  //Url
$pagearr=pagelist($pagecount,$pcount,$astr);
$offset=$pagearr[1];

$sql="select * from ld_give_help  $condition $order limit $offset,$pagecount";
$db->query($sql);
$ii=0;
foreach ($db->rs as $k => $v) {
	$ii++;
	$serialid=($pagearr[2]-1)*$pagecount+$ii;
	$rm=$member->getuv($v['uname'],'user_level');
	if($v['status']==1&&$v['had_shouyi']==1){
		$ztai="收益结束";
	}else{
		$ztai="收益中";
	}
	$tmp_arr['ttr'].='<tr class="levelcolor'.$rm['user_level'].'">
						
						<td><span  title="'.$v["id"].'">'.$serialid.'</span></td>
                                                <td>'.get_help_no("give",$v['uname'],$v['give_help_no']).'</td>    
						<td>'.$v['uname'].'</td>
						<td>'.formatdate($v['give_help_time']).'</td>
                                                <td>'.$v['amount'].'</td>
						<td >'.$v['benifit_times'].'</td>
                                                <td >'.$v['benifit_amount'].'</td>
						<td>'.$ztai.'</td>';
	$tmp_arr['ttr'].='</tr>';
}


$tmp_arr['tcount']=$pcount;
$tmp_arr['ttitle']=getmenu($GLOBALARR['menu'],'lockip');
$tmp_arr['tpage']=$pagearr[0];

function admin_huan($arr){
echo '	<h3>'.$arr['ttitle'].'</h3>
	<div class="main-r-body"><form method="get" action="?">
	<div class="main-r-item"><input type="submit" class="thabtn" value="查询"><input type="input" class="tsearch" name="quser"><span class="paixutxt">排序<span>：'.$arr['torderby'];
if(!empty($arr["twhereoption"])){
echo '<span class="colortxt">账户类型：<span>'.$arr["twhereoption"];
}
if(!empty($arr["tcolorone"])){
echo '<span class="colortxt">导出：<span>'.$arr['tcolorone'];
}
echo '</div>';
		$questr=explode("&",$_SERVER["QUERY_STRING"]);
		for($i=0;$i<count($questr);$i++){
			$questrl=explode("=",$questr[$i]);
			if(count($questrl)>0)
			{
				if($questrl[1]!=""){
					if(!($questrl[0]=="quser")){
						echo '<input type="hidden" name="'.$questrl[0].'" value="'.$questrl[1].'">';
					}
				}
			}
		}
echo '	</form><form method="post" action="'.geturl().'">
	<div class="main-r-item" '.$arr["styles"].'>'.$arr['toption'].'</div>	';

echo '<table class="thealist ttab">
		<tr>
'.$arr['tth'].'
		</tr>
		<tbody>';
if($arr['tcount']>0){
echo $arr['ttr'];
}
echo '	</tbody>					
	</table></form>';
if($arr['tcount']==0){
echo '<div class="nodata">暂无数据</div>';
}else{
echo '	<div class="pages">
		<div class="floatr">
'.$arr['tpage'].'
		</div>
	</div>	';
}

echo '</div>';
}
admin_huan($tmp_arr);
if($_GET['option'] == 1 || empty($_GET['option'])){
	$db->query("select SUM(amount) as am,SUM(benifit_amount) as bam from ld_give_help where from_unixtime(give_help_time,'%Y-%m-%d')='".date('Y-m-d')."'",2);
	$heji = $db->rs;
	echo "<div style='font-size:14px;'><span>排单金额合计：".$heji['am']."</span><b></b>&nbsp;&nbsp;&nbsp;&nbsp;<span>已分利息合计：".$heji['bam']."</span><b></b></div>";
}
if($_GET['option'] == 2){
	$db->query("select SUM(amount) as am,SUM(benifit_amount) as bam from ld_give_help",2);
	$heji = $db->rs;
	echo "<div style='font-size:14px;'><span>排单金额合计：".$heji['am']."</span><b></b>&nbsp;&nbsp;&nbsp;&nbsp;<span>已分利息合计：".$heji['bam']."</span><b></b></div>";
}
if($_GET['option'] == 3){
	$db->query("select SUM(amount) as am,SUM(benifit_amount) as bam from ld_give_help where `status`<>2 and `status`<>3 and status_value=0",2);
	$heji = $db->rs;
	echo "<div style='font-size:14px;'><span>排单金额合计：".$heji['am']."</span><b></b>&nbsp;&nbsp;&nbsp;&nbsp;<span>已分利息合计：".$heji['bam']."</span><b></b></div>";
}
if($_GET['option'] == 4){
	$db->query("select SUM(amount) as am,SUM(benifit_amount) as bam from ld_give_help where status_value=1",2);
	$heji = $db->rs;
	echo "<div style='font-size:14px;'><span>排单金额合计：".$heji['am']."</span><b></b>&nbsp;&nbsp;&nbsp;&nbsp;<span>已分利息合计：".$heji['bam']."</span><b></b></div>";
}
if($_GET['option'] == 5){
	$db->query("select SUM(amount) as am,SUM(benifit_amount) as bam from ld_give_help where `status`=2",2);
	$heji = $db->rs;
	echo "<div style='font-size:14px;'><span>排单金额合计：".$heji['am']."</span><b></b>&nbsp;&nbsp;&nbsp;&nbsp;<span>已分利息合计：".$heji['bam']."</span><b></b></div>";
}
if($_GET['option'] == 6){
	$db->query("select SUM(amount) as am,SUM(benifit_amount) as bam from ld_give_help where status_value=2",2);
	$heji = $db->rs;
	echo "<div style='font-size:14px;'><span>排单金额合计：".$heji['am']."</span><b></b>&nbsp;&nbsp;&nbsp;&nbsp;<span>已分利息合计：".$heji['bam']."</span><b></b></div>";
}
if($_GET['option'] == 7){
	$db->query("select SUM(amount) as am,SUM(benifit_amount) as bam from ld_give_help where `status`<>2 and `status`<>3 and status_value=0 and benifit_times>=".$GLOBALARR["jjsyt"]." and amount=helper_confirm_amount",2);
	$heji = $db->rs;
	echo "<div style='font-size:14px;'><span>排单金额合计：".$heji['am']."</span><b></b>&nbsp;&nbsp;&nbsp;&nbsp;<span>已分利息合计：".$heji['bam']."</span><b></b></div>";
}
?>